
using System;
using System.Web.UI.WebControls;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.EntityCollections;
using Tathata.Common.BLL.Managers;

namespace Tathata.Web.Administration.Modules
{
    public partial class SelectCategoryControl : BaseNopAdministrationUserControl
    {
        private int selectedCategoryId;

        public void BindData()
        {
            ddlCategories.Items.Clear();
            ddlCategories.Items.Add(new ListItem("[ --- ]", "0"));
            BindData(0, "--");
        }

        public void BindData(int ForParentEntityID, string prefix)
        {
            CategoryCollection categoryCollection = CategoryManager.GetAllCategories(ForParentEntityID);

            foreach (Category category in categoryCollection)
            {
                ListItem item = new ListItem(prefix + category.Name, category.CategoryID.ToString());
                this.ddlCategories.Items.Add(item);
                if (category.CategoryID == this.selectedCategoryId)
                    item.Selected = true;
                if (CategoryManager.GetAllCategories(category.CategoryID).Count > 0)
                    BindData(category.CategoryID, prefix + "--");
            }

            this.ddlCategories.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }
        
        public string CssClass
        {
            get
            {
                return ddlCategories.CssClass;
            }
            set
            {
                ddlCategories.CssClass = value;
            }
        }

        public int SelectedCategoryId
        {
            get
            {
                return int.Parse(this.ddlCategories.SelectedItem.Value);
            }
            set
            {
                this.selectedCategoryId = value;
            }
        }
    }
}